package com.kaifamiao.month03.day0331.bank.util;

import com.kaifamiao.month03.day0331.bank.model.Statement;

import java.util.Arrays;

public class ArrayListForStatement {

    Statement[] statements = new Statement[10];
    int count = 0;

    public void add(Statement statement) {
        grow();
        statements[count++] = statement;
    }

    public Statement[] indexOf(long card) {
        Statement[] sta = new Statement[count];
        int j = 0;
        for(int i = 0; i < count; i ++){
            if(statements[i].getCard() == card){
                sta[j ++] = statements[i];
            }
        }
        return Arrays.copyOf(sta,j);
    }

    // 扩容数组
    private void grow() {
        if (count == statements.length) {
            statements = Arrays.copyOf(statements, count << 1);
        }
    }

    public Statement[] findAll() {
        return Arrays.copyOf(statements, count);
    }

}
